package com.health.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.health.mapper.CheckItemMapper;
import com.health.pojo.CheckItem;
import com.health.service.CheckItemService;
import org.apache.dubbo.config.annotation.Service;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
@Transactional
public class CheckItemServiceImpl implements CheckItemService {
    @Autowired
    private CheckItemMapper checkItemMapper;

    @Override
    public void add(CheckItem checkItem) {
        checkItemMapper.insert(checkItem);
    }

    @Override
    public Page<CheckItem> pageQuery(Integer pagenum, Integer pagesize, String pageQuery) {
        QueryWrapper<CheckItem> wrapper=new QueryWrapper<>();
        Page<CheckItem> page=new Page<>(pagenum,pagesize);
        if (pageQuery!=null&&pageQuery.length()>0){
            wrapper.like("code",pageQuery).or().like("name",pageQuery);
            page=checkItemMapper.selectPage(page,wrapper);
        }else {
            page=checkItemMapper.selectPage(page,null);
        }
        return page;
    }

    @Override
    public void deleteById(Integer id) {
        long count=checkItemMapper.findCountByCheckItemId(id);
        if(count>0){
            new RuntimeException();
        }
        checkItemMapper.deleteById(id);
    }

    @Override
    public void edit(CheckItem checkItem) {
        checkItemMapper.updateById(checkItem);
    }

    @Override
    public CheckItem findById(Integer id) {
        return checkItemMapper.selectById(id);
    }

    @Override
    public List<CheckItem> findAll() {
        return checkItemMapper.selectList(null);
    }

}
